/*
 * date: 2009-11-20 
 * author: Maciej Smolenski <jezdnia@gmail.com>
 */
#include <iostream>
#include <arpa/inet.h>
#include "common.hpp"
#include "rpc_config.hpp"
#include "rpc_config_data.hpp"

#define PR(code) std::cout << code << std::endl;

namespace rc=rpc_config;

void test()
{
	rc::stdset s; 

	rc::rpc_config_service<shmda_user<rc::rpcm_config> > user(SHARE_NAME);
	for(int i=0;i<1<<0;i++)
	{
		PR("get_hosts");
		if (user.get_hosts(s)==result_failure) PR_EXIT("get_hosts", EXIT_FAILURE);
		print_set(s, "\n");
#ifdef CHECK
	sleep(4);
#endif
		rc::rpc_host_entry_string hes("jeden", 1024, IPPROTO_UDP);
		s.insert(hes);
		PR("set_hosts: {jeden}");
		if (user.set_hosts(s)==result_failure) PR_EXIT("set_hosts", EXIT_FAILURE);
#ifdef CHECK
	sleep(1);
#endif
		PR("get_hosts");
		if (user.get_hosts(s)==result_failure) PR_EXIT("get_hosts", EXIT_FAILURE);
		print_set(s, "\n");
#ifdef CHECK
	sleep(4);
#endif
		hes.address = "dwa";
		PR("add_host: dwa");
		if (user.add_host(hes)==result_failure) PR_EXIT("add_host", EXIT_FAILURE);
#ifdef CHECK
	sleep(1);
#endif
		PR("get_hosts");
		if (user.get_hosts(s)==result_failure) PR_EXIT("get_hosts", EXIT_FAILURE);
		print_set(s, "\n");
#ifdef CHECK
	sleep(4);
#endif
		hes.address = "jeden";
		PR("del_host: jeden");
		if (user.del_host(hes)==result_failure) PR_EXIT("del_host", EXIT_FAILURE);
#ifdef CHECK
	sleep(4);
#endif
		PR("get_hosts");
		if (user.get_hosts(s)==result_failure) PR_EXIT("get_hosts", EXIT_FAILURE);
		print_set(s, "\n");
#ifdef CHECK
	sleep(1);
#endif
		long delay;
		PR("get_delay");
		if (user.get_delay(delay)==result_failure) PR_EXIT("get_delay", EXIT_FAILURE);
		PR("delay " << delay);
#ifdef CHECK
	sleep(4);
#endif
		delay = 120;
		PR("set_delay: 120");
		if (user.set_delay(delay)==result_failure) PR_EXIT("set_delay", EXIT_FAILURE);
#ifdef CHECK
	sleep(1);
#endif
		PR("get_delay");
		if (user.get_delay(delay)==result_failure) PR_EXIT("get_delay", EXIT_FAILURE);
		PR("delay " << delay);
#ifdef CHECK
	sleep(4);
#endif


		long portmap_timeout;
		PR("get_portmap_timeout");
		if (user.get_portmap_timeout(portmap_timeout)==result_failure) PR_EXIT("get_portmap_timeout", EXIT_FAILURE);
		PR("portmap_timeout " << portmap_timeout);
#ifdef CHECK
	sleep(4);
#endif
		portmap_timeout = 7;
		PR("set_portmap_timeout: 7");
		if (user.set_portmap_timeout(portmap_timeout)==result_failure) PR_EXIT("set_portmap_timeout", EXIT_FAILURE);
#ifdef CHECK
	sleep(1);
#endif
		PR("get_portmap_timeout");
		if (user.get_portmap_timeout(portmap_timeout)==result_failure) PR_EXIT("get_portmap_timeout", EXIT_FAILURE);
		PR("portmap_timeout " << portmap_timeout);
#ifdef CHECK
	sleep(4);
#endif


		long ping_timeout;
		PR("get_ping_timeout");
		if (user.get_ping_timeout(ping_timeout)==result_failure) PR_EXIT("get_ping_timeout", EXIT_FAILURE);
		PR("ping_timeout " << ping_timeout);
#ifdef CHECK
	sleep(4);
#endif
		ping_timeout = 2;
		PR("set_ping_timeout: 2");
		if (user.set_ping_timeout(ping_timeout)==result_failure) PR_EXIT("set_ping_timeout", EXIT_FAILURE);
#ifdef CHECK
	sleep(1);
#endif
		PR("get_ping_timeout");
		if (user.get_ping_timeout(ping_timeout)==result_failure) PR_EXIT("get_ping_timeout", EXIT_FAILURE);
		PR("ping_timeout " << ping_timeout);
#ifdef CHECK
	sleep(4);
#endif

	}
		
}

int main(int argc, char *argv[])
{
	test();
	return 0;
}

